package myschool.array.homework;

import java.util.Arrays;
import java.util.Scanner;

public class CharacterSoringTow {
    /**
     * 在上一组的基础上，一组有序的字符序列a、b、c、e、f、p、u、z，向次字符序列中插入一个新的字符，要求插入之后字符序列仍保持有序
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        char[] character ={'a', 'c', 'u', 'b', 'e', 'p', 'f', 'z'};
        Arrays.sort(character);
        System.out.println("升序排序");
        for (int i = 0; i < character.length; i++) {
            System.out.print(character[i] + "\t");
        }
        System.out.println("");
        char tmp;
        System.out.println("请输入插入字符：");
//        String characterNo;
//        characterNo = input.next();
//        characterNo.charAt(0);选取字符串第1个出来
//        char characterNb = characterNo.charAt(0);
        char characterNb = input.next().charAt(0);
        char[] characterCopy = Arrays.copyOf(character,9);
        for (int i = 0; i < character.length-1; i++) {
            if(characterNb > character[i]){
                continue;
            }
            for (int j = characterCopy.length-1; j >= i; j--) {
                characterCopy[j] = characterCopy[j-1];

            }
            characterCopy[i] = characterNb;
            break;

        }
        System.out.println("排序");
        for (int i = 0; i < characterCopy.length; i++) {
            System.out.print(characterCopy[i] + "\t");
        }
    }

}
